#ifndef _GENERATOR_HPP_
#define _GENERATOR_HPP_

// presentation swf type

#include "include.hpp"
#include "item.hpp"

class xlider_generator:public xlider_class {

public:

	vector<string> lines;
	// copy constructor
	xlider_item* it;

	void set_item(xlider_item* ite) {
		it=ite;
		slide_width=it->slide_width;
		slide_height=it->slide_height;
		margin_top=it->margin_top;
		margin_left=it->margin_left;
		margin_right=it->margin_right;
		home_path=it->home_path;
	}	

	virtual double get_x(){return it->x*it->slide_width;}
	virtual double get_y(){return it->y*it->slide_height;}	
	virtual double get_height(){return it->height*it->slide_height;}
	virtual double get_width(){return it->width*it->slide_width;}
	virtual double get_indent(){return it->indent*it->slide_width;}
	virtual double get_offsetx(){return it->offsetx*it->slide_width;}
	virtual double get_offsety(){return it->offsety*it->slide_height;}
	virtual int    get_level(){return it->level;}
	virtual double get_spacing(){return it->spacing*it->slide_height;}
	virtual double get_distance(){return it->distance*it->slide_height;}
	virtual bool   get_floating(){return it->floating;}
	virtual string get_bullet_color(){return it->bullet_color;}
	virtual string get_bullet_type(){return it->bullet_type;}
	virtual double get_bullet_radius(){return it->bullet_radius*it->slide_width;}
	virtual double get_bullet_space(){return it->bullet_space*it->slide_width;}
	virtual string get_text(){return it->text;}
	virtual void   set_textwidth(double wdt){it->width=wdt;}
	virtual string get_align(){return it->align;}
	virtual double get_fontsize(){return it->fontsize*it->slide_height;}
	virtual string get_fontname(){return it->fontname;}
	virtual string get_fontcolor(){return it->fontcolor;}
	virtual void set_width(double w){it->width=w/it->slide_width;}
	virtual void set_height(double h){it->height=h/it->slide_height;}
	virtual void set_offset(double ox, double oy){
		it->offsetx=ox/it->slide_width;
		it->offsety=oy/it->slide_height;
	}

	// this function must return null on failure
	virtual void* generate(void* param)=0;
	virtual double draw(void* draw_param)=0;

	double get_line_offset() {
		if(get_bullet_type()!=""&&get_bullet_type()!="none") {
			return (2.0*get_bullet_radius()+get_bullet_space());
		}
		return 0.0;
	}
	
	virtual void arrange_text() {
		lines.clear();
		string text=get_text();
		trim(text);
		int v=0;
		
		for(int i=0;i<=text.length();i++){
			if(text[i]=='\n'||text[i]=='\0'){
				string curline=text.substr(v,i-v);
				trim(curline);
				lines.push_back(curline);
				v=i+1;
			}
		}
	}
	
	virtual double get_shiftx(double tlen){
		if(get_align()=="left")  return(get_offsetx()+get_line_offset());
		if(get_align()=="right") return(get_width()-tlen);
		if(get_align()=="center")return((get_width()-tlen)/2.0);
	}
	
	virtual double get_shifty(double nline){
		return (get_offsety()+get_fontsize()*nline+get_spacing());
	}
	
	virtual double get_actual_height(){
		return ((double)lines.size()*(get_fontsize()+get_spacing())+get_distance());
	}

};

#endif
